<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>参数传递</title>
</head>
<body>
    <div id="app1"></div>
    <div id="app2"></div> 
    <div id="app3"></div> 
    <script src="../react-lib/babel.min.js"></script>
    <script src="../react-lib/react.development.js"></script>
    <script src="../react-lib/react-dom.development.js"></script> 
    <!-- 使用 PropTypes 进行类型检查 -->
    
    <script src="../react-lib/prop-types.js"></script> 
    <script type="text/babel">
    class TestComponent extends React.Component{
        constructor(props){
            super(props)
            this.showInput1 = this.showInput1.bind(this)
            this.showInput2 = this.showInput2.bind(this)
        }
        showInput1(){
            alert(this.refs.input1.value)
        }
        showInput2(){
            alert(this.input.value)
        }
        handleBlur(event){ 
            alert(event.target.value)
        }
        render(){
            return (
                <div>
                    {/** 可用写法*/}
                    <input type="text" ref="input1" placeholder="可用写法"/>
                    <button onClick={this.showInput1}>提示输入1</button>
                    {/** 官方建议写法*/} 
                    <input type="text" ref={(input)=>this.input = input}  placeholder="官方建议写法"/>
                    <button onClick={this.showInput2}>提示输入2</button>

                    <input type="text" placeholder="失去焦点" onBlur={this.handleBlur}/>
                </div>
            )
        }

    }
    ReactDOM.render(<TestComponent/>,document.getElementById('app1'))
    </script>
</body>
</html>